Omplus.base.define(Omplus.controllers.Controller, {
    omplusName:"bonusesController"
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"BonusesSearch",
    controller:"bonusesController",
    value:{
        bonus_status:{
            omplusType:"String",
            synchroniseWith:"BonusStatuses.current.code"
        },
        activation_type: {
            omplusType:"String",
            synchroniseWith:"BonusActivations.current.code"
        },
        reward_type: {
            omplusType:"String",
            synchroniseWith:"BonusRewards.current.code"
        },
        delta:{
            omplusType:"Number",
            value:5
        },
        start:{
            omplusType:"Number",
            value:0
        }
    }
});

Omplus.models.BonusSearchModelProto = Omplus.base.extend(Omplus.models.Object, {
    omplusType:"BonusSearchModelProto",
    value:{
        "bonus_id":{
            omplusType:"Number"
        },
        "name":{
            omplusType:"String"
        },
        "launch_date":{
            omplusType:"DateTime"
        },
        expire_date:{
            omplusType:"DateTime"
        },
        status:{
            omplusType:"String"
        },
        activation_type:{
            omplusType:"String"
        },
        reward_type:{
            omplusType:"String"
        }
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"BonusSearchResults",
    controller:"bonusesController",
    value:{
        bonuses:{
            omplusType:"Array",
            omplusProto:"BonusSearchModelProto"
        },
        total:{
            omplusType:"Number"
        }
    }
});

Omplus.models.BonusesProto = Omplus.base.extend(Omplus.models.Model, {
    omplusType:"BonusesProto",
    value:{
        "bonus_id":{
            omplusType:"Number"
        },
        "name":{
            omplusType:"String"
        },
        "launch_date":{
            omplusType:"DateTime"
        },
        expire_date:{
            omplusType:"DateTime"
        },
        bonus_status:{
            omplusType:"String"
        },
        activation_type:{
            omplusType:"String"
        },
        reward_type:{
            omplusType:"String"
        }
    }
});

Omplus.views.OpeningBonusTabView = Omplus.base.extend(Omplus.views.OpeningTabView, {
    omplusType:"OpeningBonusTabView",
    layout:{
        omplusType:"HorizontalLayout",
        width: "900px"
    },
    controller:"bonusesController",
    components:[
        {
            omplusType:"Panel",
            omplusName:"BonusesTabLeft",
            width:"300px",
            layout:{
                omplusType:"VerticalLayout"
            },
            components:[
                {
                    model:"bonusChooser.current.bonus_id",
                    labelModel:"Assets.list.bonus_id_label.localValue",
                    inputType:"Label",
                    height: "40px"
                },
                {
                    model:"bonusChooser.current.bonus_status",
                    labelModel:"Assets.list.status_label.localValue",
                    inputType:"Label",
                    height: "40px"
                },
                {
                    model:"bonusChooser.current.name",
                    labelModel:"Assets.list.name_label.localValue",
                    inputType:"Label",
                    height: "40px"
                }
            ]
        }
    ]
});

Omplus.base.define(Omplus.models.SingleChooser, {
    omplusName:"bonusChooser",
    controller:"bonusesController",
    omplusProto:"BonusesProto"
});

Omplus.base.define(Omplus.views.ManagementPanel, {
    omplusName:"bonusesPanel",
    controller:"bonusesController",
    renderTo:"managements",
    models:{
        chooser:"bonusChooser",
        search:"BonusesSearch",
        searchResult:"BonusSearchResults",
        searchResultList:"bonuses",
        forDisplay:"name"
    },
    views:{
        chooser:{
            title:"Assets.list.bonuses_label.localValue",
            components:[
                {
                    omplusName:"bonusTabs",
                    omplusType:"OpeningTabPanel",
                    omplusProto:"OpeningBonusTabView",
                    controller:"bonusesController",
                    model:"bonusChooser",
                    showModel:"name"
                }
            ]
        },
        search:[
            {
                inputType:"Select",
                omplusName:"chooseStatusBonus",
                model:"BonusStatuses",
                current: "current",
                showModel:"name",
                labelModel:"Assets.list.bonus_activation_label.localValue",
                controller:"languageController"
            },
            {
                inputType:"Select",
                omplusName:"chooseActivationBonus",
                model:"BonusActivations",
                current: "current",
                showModel:"name",
                labelModel:"Assets.list.status_label.localValue",
                controller:"languageController"
            },
            {
                inputType:"Select",
                omplusName:"chooseRewardBonus",
                model:"BonusRewards",
                current: "current",
                showModel:"name",
                labelModel:"Assets.list.bonus_reward_label.localValue",
                controller:"languageController"
            },
            {
                inputType:"Select",
                model:"PerPages",
                showModel:"number",
                current:"forBonuses",
                controller:"languageController",
                labelModel:"Assets.list.label_per_page.localValue",
                perPage:true
            },
            {
                inputType:"Button",
                controller:"languageController",
                model:"Assets.list.label_search_button.localValue",
                cssClasses:["search-button"],
                labelWidth:"0%",
                inputWidth:"100%",
                searchButton:true
            }
        ],
        searchResult:[
            {
                labelModel:"Assets.list.bonus_id_label.localValue",
                width:"80px",
                omplusType:"Label",
                model:"bonus_id"
            },
            {
                labelModel:"Assets.list.status_label.localValue",
                width:"100px",
                omplusType:"Label",
                model:"status"
            },
            {
                labelModel:"Assets.list.name_label.localValue",
                width:"300px",
                omplusType:"Label",
                model:"name"
            },
            {
                labelModel:"Assets.list.launch_date_label.localValue",
                width:"100px",
                omplusType:"Label",
                model:"launch_date"
            },
            {
                labelModel:"Assets.list.expire_date_label.localValue",
                width:"100px",
                omplusType:"Label",
                model:"expire_date"
            },
            {
                omplusType:"Button",
                model:"Assets.list.details_label.localValue",
                width:"250px",
                controller:"languageController",
                getDetails:true
            }
        ]
    }
});